﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace KinectGestureRecognizer.HUD
{
    public class AnimatedTextAlert
    {
        TimeSpan duration, creationTime;
        String textToDraw;
        float scale;

        public bool shouldBeDisposed { get; set; }

        public AnimatedTextAlert(GameTime gameTime, TimeSpan duration, String textToDraw)
        {
            this.duration = duration;
            this.creationTime = gameTime.TotalGameTime;
            this.textToDraw = textToDraw;
        }

        public void Update(GameTime gameTime)
        {
            if (duration.TotalMilliseconds > gameTime.TotalGameTime.TotalMilliseconds - creationTime.TotalMilliseconds)
            {
                scale = (float)((gameTime.TotalGameTime.TotalMilliseconds - creationTime.TotalMilliseconds) / duration.TotalMilliseconds);
            }
            else
                shouldBeDisposed = true;
        }

        public void Draw(SpriteBatch spriteBatch, SpriteFont font, Vector2 position)
        {
            var center = font.MeasureString(textToDraw) / 2;
            
            spriteBatch.DrawString(font, textToDraw, position, Color.White * (1 - scale), 0, center, scale, SpriteEffects.None, 0);
        }
    }
}
